Tx Builder¶
tx_builder is a collection of useful functions for instantiating transactions or components of transactions. As opposed to Simple, tx_builder offers more low-level control, and accepts instantiated or components rather than human-readable ones.
-
riemann.tx.tx_builder.length_prepend(byte_string: bytes) → bytes¶ Adds a VarInt length marker to a bytestring
-
riemann.tx.tx_builder.make_decred_input(outpoint: riemann.tx.decred.DecredOutpoint, sequence: int) → riemann.tx.decred.DecredTxIn¶
-
riemann.tx.tx_builder.make_decred_witness(value: bytes, height: bytes, index: bytes, stack_script: bytes, redeem_script: bytes) → riemann.tx.decred.DecredInputWitness¶ Decred has a unique witness structure.
-
riemann.tx.tx_builder.make_empty_witness() → riemann.tx.tx.InputWitness¶ Create an InputWitness with an empty stack. Useful for unsigned transactions, as well as Legacy inputs in Segwit transactions. By consensus, if any witness is present, all inputs must have a witness.
-
riemann.tx.tx_builder.make_legacy_input(outpoint, stack_script, redeem_script, sequence)¶ Make a legacy input. This supports creating Compatibility inputs by passing the witness program to redeem_script while passing an empty bytestring for stack_script.
- Parameters
outpoint – The Outpoint object
stack_script – A serialized Script program that sets the initial stack
redeem_script – A serialized Script program that is run on the stack
sequence – The 4-byte LE-encoded sequence number
- Returns
A Legacy TxIn object.
-
riemann.tx.tx_builder.make_op_return_output(data: bytes) → riemann.tx.tx.TxOut¶ Generates OP_RETURN output for data of up to 77 bytes. OP_RETURN outputs are data carriers with no impact on the UTXO set. They are comonly used to create on-chain commitments to some off-chain information. There are few consensus constraints on their content or structure, however they become non-standard above 77 bytes.
- Parameters
data (bytes) – data to be included in output
- Returns
TxOut object with OP_RETURN output
- Return type
(TxOut)
-
riemann.tx.tx_builder.make_outpoint(tx_id_le, index, tree=None)¶ Instantiate an Outpoint object from a transaction id and an index.
- Parameters
tx_id_le – The 32-byte LE hash of the transaction that created the prevout being referenced.
index – The index of the TxOut that created the prevout in its transaction’s output vector
tree – Only in Decred transactions. Specifies the commitment tree.
- Returns
An Outpoint object. If network is set to Decred, a DecredOutpoint
-
riemann.tx.tx_builder.make_p2pkh_output(value: int, pubkey: bytes) → riemann.tx.tx.TxOut¶ Instantiates a P2PKH TxOut from value and raw pubkey.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
pubkey – The 33- or 65-byte raw public key.
- Returns
A TxOut object paying a P2PKH script pubkey
-
riemann.tx.tx_builder.make_p2pkh_output_script(pubkey: bytes) → bytes¶ Makes a P2PKH script pubkey from a raw public key.
- Parameters
pubkey – The 33- or 65-byte public key.
- Returns
The P2PKH script pubkey containing the hash of the pubkey.
-
riemann.tx.tx_builder.make_p2sh_output(value: int, output_script: str) → riemann.tx.tx.TxOut¶ Instantiates a P2SH TxOut from value and human-readable Script.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
output_script – The non-length-prepended output script.
- Returns
A TxOut object paying a P2SH script pubkey.
-
riemann.tx.tx_builder.make_p2sh_output_script(script_string: str) → bytes¶ Make a P2SH script pubkey from a human-readable Script.
- Parameters
script_string – The human-readable redeem script.
- Returns
The P2SH script pubkey containing the hash of the serialized script.
-
riemann.tx.tx_builder.make_p2wpkh_output(value: int, pubkey: bytes) → riemann.tx.tx.TxOut¶ Instantiates a P2WPKH TxOut from value and raw pubkey.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
pubkey – The 33- or 65-byte raw public key.
- Returns
A TxOut object paying a P2WPKH script pubkey
-
riemann.tx.tx_builder.make_p2wpkh_output_script(pubkey: bytes) → bytes¶ Makes a P2PKH or P2WPKH script pubkey from a raw public key. Does not support Compatibility p2wsh-via-p2sh output scripts.
- Parameters
pubkey – The 33- or 65-byte public key.
- Returns
The P2WPKH script pubkey containing the hash of the pubkey.
-
riemann.tx.tx_builder.make_p2wsh_output(value: int, output_script: str) → riemann.tx.tx.TxOut¶ Instantiates a P2WSH TxOut from value and human-readable Script.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
output_script – The non-length-prepended output script.
- Returns
A TxOut object paying a P2WSH script pubkey.
-
riemann.tx.tx_builder.make_p2wsh_output_script(script_string: str) → bytes¶ Make a P2WSH script pubkey from a human-readable Script. Does not support Compatibility p2wsh-via-p2sh output scripts.
- Parameters
script_string – The human-readable witness script.
- Returns
The P2WSH script pubkey containing the hash of the serialized script.
-
riemann.tx.tx_builder.make_pkh_output(value: int, pubkey: bytes, witness: bool = False) → riemann.tx.tx.TxOut¶ Instantiates a P2PKH or P2WPKH TxOut from value and raw pubkey.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
pubkey – The 33- or 65-byte raw public key.
witness – Pass True to make a P2WPKH script pubkey.
- Returns
A TxOut object
-
riemann.tx.tx_builder.make_pkh_output_script(pubkey: bytes, witness: bool = False) → bytes¶ Makes a P2PKH or P2WPKH script pubkey from a raw public key. Does not support Compatibility p2wpkh-via-p2sh output scripts.
- Parameters
pubkey – The 33- or 65-byte public key.
witness – Pass True to make a P2WSH script pubkey.
- Returns
The script pubkey containing the hash of the pubkey.
-
riemann.tx.tx_builder.make_script_sig(stack_script: str, redeem_script: str) → bytes¶ Make a serialized script sig from a human-readable stack script and redeem script.
-
riemann.tx.tx_builder.make_sh_output(value: int, output_script: str, witness: bool = False) → riemann.tx.tx.TxOut¶ Instantiates a P2SH or P2WSH TxOut from value and human-readable Script.
- Parameters
value – The 8-byte LE-encoded integer value of the output.
output_script – The non-length-prepended human-readable Script.
witness – Pass True to make a P2WSH script pubkey.
- Returns
A TxOut object
-
riemann.tx.tx_builder.make_sh_output_script(script_string: str, witness: bool = False) → bytes¶ Make a P2SH or P2WSH script pubkey from a human-readable script. Does not support Compatibility p2wsh-via-p2sh output scripts.
- Parameters
script_string – The human-readable redeem script or witness script.
witness – Pass True to make a P2WSH script pubkey.
- Returns
The script pubkey containing the hash of the serialized script.
-
riemann.tx.tx_builder.make_sh_script_pubkey(script_bytes: bytes, witness: bool = False) → bytes¶ Make a P2SH or P2WSH script pubkey from a serialized script. Does not support Compatibility p2wsh-via-p2sh output scripts.
- Parameters
script_bytes – The serialized redeem script or witness script.
witness – Pass True to make a P2WSH script pubkey.
- Returns
The script pubkey containing the hash of the serialized script.
-
riemann.tx.tx_builder.make_tx(version, tx_ins, tx_outs, lock_time, expiry=None, value_balance=0, tx_shielded_spends=None, tx_shielded_outputs=None, tx_witnesses=None, tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None, binding_sig=None)¶ Instantiate a complete Tx object from its components.
- Parameters
version – The 4-byte LE-encoded version number.
tx_ins – A list of TxIn objects.
tx_outs – A list of TxOut objects.
lock_time – The 4-byte LE-encoded lock_time number.
expiry – Decred, Overwinter, and Sapling only. 4-byte LE expiry number.
value_balance – Sapling only. An 8-byte LE number representing the net change in shielded pool size as a result of this transaction.
tx_shielded_spends – Sapling only. An array of SaplingShieldedSpend.
tx_shielded_outputs – Sapling only. An array of SaplingShieldedOutput.
tx_witnesses – An array of InputWitness objects.
tx_joinsplits – Sprout, Overwinter, and Sapling only. An array of SproutJoinsplit or SaplingJoinsplit objects.
joinsplit_pubkey – The joinsplit pubkey. See Zcash protocol docs.
joinsplit_sig – The joinsplit signature. See Zcash protocol docs.
binding_sig – The binding signature. See Zcash protocol docs.
- Returns
A Tx object. DecredTx if network is set to Decred. SproutTx if set to Zcash Sprout. OverwinterTx if set to Zcash Overwinter. SaplingTx if set to Zcash Sapling.
-
riemann.tx.tx_builder.make_witness(data_list: List[bytes]) → riemann.tx.tx.InputWitness¶ Make a witness stack from a list of bytestrings. Each bytestring is wrapped in a WitnessStackItem object and places into the InputWitness in order
-
riemann.tx.tx_builder.make_witness_input(outpoint, sequence)¶ Make a Segwit input. This is clearly superior to make_legacy_input and you should use witness always.
- Parameters
outpoint – The Outpoint object
sequence – The 4-byte LE-encoded sequence number
- Returns
A Segwit TxIn object.
-
riemann.tx.tx_builder.make_witness_stack_item(data: bytes) → riemann.tx.tx.WitnessStackItem¶ Wrap a bytestring in a WitnessStackItem object